const save = {
  state: {
    tagslist: [
      {
        path: '/',
        redirect: '/mainIndex',
        name: '系统首页'
      }
    ],
    commonTabInfo: {
      text: '',
      tabsName: 'first',
      custom: ''
    } // 页面tab传递数据
  },
  mutations: {
    SET_TAGSLIST: (state, routerInfo) => {
      var flag = true
      if (state.tagslist && state.tagslist.length === 0) {
        state.tagslist.push(routerInfo)
      } else {
        for (var i = 0; i < state.tagslist.length; i++) {
          if (!routerInfo.name || state.tagslist[i].name === routerInfo.name) {
            flag = false
            break
          }
        }
        if (flag) {
          state.tagslist.push(routerInfo)
          if (state.tagslist.length > 10) {
            state.tagslist.splice(1, 1)
          }
        }
      }
    },
    SET_COMMONTABINFO: (state, commonTabInfo) => {
      state.commonTabInfo = commonTabInfo
    }
  },

  actions: {
    // 登录获取侧边栏
    SetTagsList({ commit }, routerInfo) {
      commit('SET_TAGSLIST', routerInfo)
    },
    // 设备tab操作
    handleTabInfo({ commit }, eventInfo) {
      commit('SET_COMMONTABINFO', eventInfo)
    }
  }
}

export default save
